AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init.lua")

include("shared.lua")

ENT.DieTime = 0
ENT.Setup = false
ENT.Life = 0.9
ENT.Damage = 0

function ENT:Initialize()
	self.Entity:PhysicsInitSphere(self.fRad,"default_silent")
	self.Entity:SetSolid(SOLID_BBOX)
	self.Entity:SetCollisionBounds(Vector() * -self.fRad,Vector() * self.fRad)
	--self.Entity:SetCollisionGroup(COLLISION_GROUP_WEAPON)
	self.Entity:SetNotSolid(true)
	self.Entity:SetTrigger(true)
	self.Entity:DrawShadow(false)
	local phy = self.Entity:GetPhysicsObject()
	if phy:IsValid() then
		phy:SetMass(0.03)
		phy:SetDamping(2.5,5)
		phy:Wake()
	end
	self.DieTime = CurTime() + self.Life
	self.Setup = true
end

function ENT:SetDamage(dmg)
	self.Damage = dmg
end

function ENT:SetBurnTime(bt)
	self.BurnTime = bt
end

function ENT:Think()
	if (self.Setup && CurTime() > self.DieTime) then
		self:Remove()
	end
end

function ENT:PhysicsCollide(data,phys)
	self:Firefy(data.HitEntity)
end

function ENT:Firefy(other)
	if !(other && other:IsValid()) then return end
	local oc = other:GetClass()
	if oc == "advturret_flamelet" || string.find(oc,"adv_") || oc == "flame" || string.find(oc,"gmod_") then return end
	if !other:IsWorld() then
		if other:WaterLevel() > 1 then return end
		util.BlastDamage(self:GetOwner(), self:GetOwner().TurretOwner, self:GetPos(),3,self.Damage)
		if other:IsNPC() then
			other:Fire("ignite","",0)
		end
		if other:IsPlayer() then
			other:SetDSP(1,false)
			other:Ignite(self.BurnTime,0)
		end
	end
	self:Fire("kill",0,0)
end

function ENT:Touch(other)
	self:Firefy(other)
end

hook.Add("PlayerSpawn","NoEternalFlameThankYou",function(pl) pl:Extinguish() end)

hook.Add("Think","WaterNeedsOxygenToo",function() for k,p in pairs(player.GetAll()) do if p:WaterLevel() > 1.5 and p:IsOnFire() then p:Extinguish() end end end)